package io.renren.modules.dangan.controller;

import java.util.Arrays;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.annotation.FlhFilter;
import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import io.renren.modules.dangan.entity.DaWsEntity;
import io.renren.modules.dangan.service.DaWsService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * ${comments}
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2019-08-03 22:04:02
 */
@RestController
@RequestMapping("/daws")
@CrossOrigin
public class DaWsController {
    @Autowired
    private DaWsService daWsService;


    /**
     * 列表
     */
    @RequestMapping("/list")
//    @RequiresPermissions("dangan:daws:list")
    @FlhFilter
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = daWsService.queryPage(params);
        return R.ok().put("page", page);
    }
    @RequestMapping("/getJs")
    public R getJs(@RequestParam Map<String, Object> params){
        Integer js= daWsService.getJs(params);
        return R.ok().put("js",js);
    }

    @RequestMapping("/guiDang")
    public R guiDang(@RequestParam Map<String, Object> params){
        DaWsEntity daWsEntity= daWsService.guiDang(params);
        return R.ok().put("wsDangan",daWsEntity);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{nbxh}")
    @RequiresPermissions("dangan:daws:info")
    public R info(@PathVariable("nbxh") String nbxh){
        DaWsEntity daWs = daWsService.getById(nbxh);

        return R.ok().put("daWs", daWs);
    }
    /**
     * 保存
     */
    @RequestMapping("/save")
//    @RequiresPermissions("dangan:daws:save")
    public R save(@RequestBody DaWsEntity daWs){
        daWsService.save(daWs);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
//    @RequiresPermissions("dangan:daws:update")
    public R update(@RequestBody DaWsEntity daWs){
        ValidatorUtils.validateEntity(daWs);
//        daWsService.updateById(daWs);
        daWsService.update(daWs,new QueryWrapper<DaWsEntity>().eq("nbxh",daWs.getNbxh()));
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("dangan:daws:delete")
    public R delete(@RequestBody String[] nbxhs){
        daWsService.removeByIds(Arrays.asList(nbxhs));

        return R.ok();
    }
    /**
     * 删除
     */
    @RequestMapping("/deleteByNbxh")
    public R deleteByNbxh(@RequestParam Map<String, Object> params){
        daWsService.delete(params);

        return R.ok();
    }
}
